% This script loads the predicted Dst from LASP
% And interpolate the data to the time axis defined in fday%


clear all;
%close all; clc;

%storm_month = datenum(2000,4,1); 
%storm_month = datenum(2000,7,8);
%storm_month = datenum(2000,8,8);
storm_month = datenum(2001,3,30);
%storm_month = datenum(2003,10,30);
%storm_month = datenum(2003,11,18);

load(['/Users/manojnair/data/obs_elec_data/storm_selected_data/obs_elec_' datestr(storm_month,'mmmyy') '.mat'],'fday');


S = urlread('http://lasp.colorado.edu/space_weather/dsttemerin/archive/dst_2001_03.txt');

[A,B] = textscan(S(35:end),'%s','delimiter','\n');

for i = 1:length(A{1}),
     data(i,:) = A{1}{i};
end;

year = str2num(data(:,1:4));
dayofyear = str2num(data(:,6:8));
hour = str2num(data(:,10:11));
minute =  str2num(data(:,13:14));
seconds =str2num(data(:,16:17));
Dst = str2num(data(:, 19:end));
fday_dst = datenum(year,0, dayofyear, hour, minute, seconds);


S = urlread('http://lasp.colorado.edu/space_weather/dsttemerin/archive/dst_2001_04.txt');

[A,B] = textscan(S(35:end),'%s','delimiter','\n');
clear  data;

for i = 1:length(A{1}),
     data(i,:) = A{1}{i};
end;

year = str2num(data(:,1:4));
dayofyear = str2num(data(:,6:8));
hour = str2num(data(:,10:11));
minute =  str2num(data(:,13:14));
seconds =str2num(data(:,16:17));
Dst1 = str2num(data(:, 19:end));
fday_dst1 = datenum(year,0, dayofyear, hour, minute, seconds);
fday_dst = [fday_dst;fday_dst1]';

Dst = [Dst; Dst1]';

%plot(fday_dst, Dst);

p_dst = -interp1(fday_dst, Dst, fday);
p_dst = reshape(p_dst, [14400,1]);

save /Users/manojnair/projects/GIC/pdst_2001_03 p_dst;